package com.atguigu.three;

import com.atguigu.util.RabbitMqUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.util.Scanner;

/**
 * @author gan
 * @create 2021-07-03 16:40
 * 消息在手动应答时是不丢失，放回队列中重新消费
 */
public class Task02 {

    public static final String TASK_QUEUE_NAME = "ack_queue";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //声明队列
        boolean durable = true; //需要让Queue进行持久化
        channel.queueDeclare(TASK_QUEUE_NAME, durable, false, false, null);

        Scanner sc = new Scanner(System.in);

        System.out.println("请输入信息");

        while(sc.hasNext()){
            String message = sc.nextLine();

//            channel.basicPublish("", TASK_QUEUE_NAME, null, message.getBytes("UTF-8"));

            //设置生产者发送消息为持久化消息（要求保存到磁盘中）保存到内存中
            channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,
                    message.getBytes("UTF-8"));
            System.out.println("生产者发出消息" + message);
        }
    }
}
